package cn.xz.zysjz.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.os.Build;
import android.os.Bundle;
import android.view.WindowManager;

import java.util.ArrayList;

import cn.xz.zysjz.R;
import cn.xz.zysjz.bean.CommonLib;
import cn.xz.zysjz.bean.UserBean;
import cn.xz.zysjz.databinding.ActivityZcactivityBinding;
import cn.xz.zysjz.utils.SessionUtils;
import cn.xz.zysjz.utils.ToastUtils;

public class ZCActivity extends AppCompatActivity {

    ActivityZcactivityBinding mBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_zcactivity);
        if (Build.VERSION.SDK_INT >= 21) {
            this.getWindow()
                    .setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
        initEvent();
    }

    private void initEvent(){
        //返回
        mBinding.viewBack.setOnClickListener(v->{
            finish();
        });
        //点击注册
        mBinding.tvDl.setOnClickListener(v->{
            //用户名
            String name = mBinding.etName.getText().toString();
            //密码
            String pwd = mBinding.etPwd.getText().toString();
            //再次密码
            String pwd2 = mBinding.etPwd2.getText().toString();
            //年龄
            String old = mBinding.etOld.getText().toString();

            if (name.equals("")){
                ToastUtils.show("请输入用户名");
                return;
            }
            if (pwd.equals("")){
                ToastUtils.show("请输入密码");
                return;
            }
            if (pwd2.equals("")){
                ToastUtils.show("请输入确认密码");
                return;
            }
            if (old.equals("")){
                ToastUtils.show("请输入年龄");
                return;
            }
            if (!pwd.equals(pwd2)){
                ToastUtils.show("两次密码输入不一致");
                return;
            }
            UserBean userBean = new UserBean();
            userBean.setPic("");
            userBean.setName(name);
            userBean.setOld(old);
            userBean.setPwd(pwd);
            userBean.setPass(false);
            userBean.setSj(false);
            ArrayList<UserBean> userList = SessionUtils.getList(CommonLib.USER_DATA, UserBean.class);
            userList.add(userBean);
            SessionUtils.commitList(CommonLib.USER_DATA,userList);

            ToastUtils.show("注册成功");
            finish();
        });
    }
}